import React, { useMemo } from 'react';
import { Form } from 'antd';
import { TreeSelectMultipleTile } from '@/components';
import { useFetchDutyData } from '@/components/OrgSelector';
import { preprocessDataItem } from '@/components/OrgSelector/util';

// 权限管理-模板编辑-授权岗位
const AuthorizedPost = ({ form }) => {
    const { data: dutyData, loading: dutyLoading } = useFetchDutyData();
    const processedData = useMemo(
        () =>
            preprocessDataItem(dutyData, {
                isDeleteInvalidNode: true
            }) || [],
        [dutyData]
    );
    return (
        <Form.Item style={{ display: 'flex', justifyContent: 'center', paddingTop: 52 }}>
            {form.getFieldDecorator('dutyCodeList')(
                <TreeSelectMultipleTile
                    style={{ width: 592 }}
                    data={processedData || []}
                    loading={dutyLoading}
                    isPreviewByGroup
                    previewSortType="asc"
                />
            )}
        </Form.Item>
    );
};

export default AuthorizedPost;
